<template>
  <div>
    <div class="table-box">
      <el-table
        v-loading="loading"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column prop="name" label="工具名称" align="center" />
        <el-table-column prop="createTime" label="提交审核时间" align="center" />
        <el-table-column prop="createDeptName" label="提供部门" align="center" />
        <el-table-column prop="statusName" label="审核状态" align="center" />

        <el-table-column label="操作" fixed="right" width="160px">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="dialogDetail(scope.row)"
            >查看详情</el-button>
            <el-button
              v-if="scope.row.status === 'in_review'"
              type="text"
              color="#0DB493"
              @click="handleAudit(scope.row)"
            >立即审核</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <PublishAuditForm ref="PublishToolForm" title="数据工具发布审核" @save="handleSave" />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import PublishAuditForm from './publish-audit-form/toolForm'
import { http_serve_sub_tool_publish_audit } from '@/api'
import { mapGetters } from 'vuex'
export default {
  name: 'PublishPage',
  components: {
    PublishAuditForm
  },
  mixins: [crud],
  props: {
    params: Object
  },
  computed: {
    ...mapGetters(['enum']),
    statusList() {
      return this.enum['AuditDataStatusType'] || []
    }
  },
  data() {
    return {
      request: http_serve_sub_tool_publish_audit
    }
  },
  methods: {
    formatTableData(data) {
      data.forEach(v => {
        v.statusName = this.statusList.find(e => e.value === v.status).name
      })
    },
    getQueryParams() {
      const params = {
        pageNum: this.pageNo,
        pageSize: this.pageSize
      }
      for (const paramsKey in this.params) {
        if (paramsKey === 'timeValue') {
          if (!this.params[paramsKey] || !this.params[paramsKey].length) {
            this.params[paramsKey] = ['', '']
          }
          params['startTime'] = this.params.timeValue[0] || undefined
          params['endTime'] = this.params.timeValue[1] || undefined
        } else {
          params[paramsKey] = this.params[paramsKey]
        }
      }
      return params
    },
    // 详情
    dialogDetail(item) {
      this.$router.push({
        path: '/serve-publish/tool-detail/publish/' + item.id + '/' + (item.auditRequestId || '')
      })
    },
    handleAudit(item) {
      this.$refs.PublishToolForm.open(item)
    },
    handleSave() {
      this.initData()
    }
  }
}
</script>

<style scoped>

</style>
